<?php

namespace App\Http\Controllers\Index;
use App\Facades\Site;
use Style,DB,Config;
use Illuminate\Http\Request;

use App\Models\Common\CollArea;
use App\Models\Common\CollOption;
use App\Models\Common\CollPosition;
use App\Models\Common\CollTwoOption;

use App\Models\Common\English\EnCollArea;
use App\Models\Common\English\EnCollOption;
use App\Models\Common\English\EnCollPosition;
use App\Models\Common\English\EnCollTwoOption;
use App\Models\Personal\Resume;
use App\Models\Personal\ResumeRemark;
use App\Models\Personal\ResumeSend;
use App\Models\Personal\ResumeCertificate;
use App\Models\Personal\ResumeEducationExp;
use App\Models\Personal\ResumeExtra;
use App\Models\Personal\BrowseResume;
use App\Models\Personal\ResumeLanguageSkill;
use App\Models\Personal\ResumeOther;
use App\Models\Personal\ResumeProjectExp;
use App\Models\Personal\ResumeSkill;
use App\Models\Personal\ResumeWorkExp;
use App\Models\Personal\ResumeWorks;
use App\Models\Personal\ResumeWorksImg;
use  App\Models\Company\CompanyUser;
use  App\Models\Company\CompanyBasic;
use  App\Models\Company\CompanyJob;
use  App\Models\Company\BuyResume;
use App\Models\Company\ResumeFavorite;

class ResumeController extends CommonController{

    /**简历英文**/
    public function english($resume,Request $request){

        //用户ID
        $suid =  $request->input('suid');
        //读取基本信息
        $id = $resume->id;//resume_status

        //判断能浏览简历的参数 管理员可以，自己可以，简历状态为1
        $user=auth()->guard('company')->user();//企业登录
        if(auth()->guard('company')->check()){
            $CompanyBasic = CompanyBasic::select("id")->where("uid",$user->uid)->orderBy("updatetime","desc")->first();//是否给企业投递过简历
            if($CompanyBasic){
                if(ResumeSend::where("company_uid",$user->uid)->where("com_id",$CompanyBasic->id)->where("personal_uid",$resume->uid)->where("resume_id",$id)->count()){
                    $companyLookResume = 1;
                }else{
                    $companyLookResume = 0;
                }
            }else{
                $companyLookResume = 0;
            }
        }else{
            $companyLookResume = 0;
        }

        if(auth()->guard('personal')->check()){//用户登录
            $personalUid = auth()->guard('personal')->user()->uid;
        }else{
            $personalUid = '';
        }

        //判断条件是否有权浏览
        if($personalUid == $resume->uid || auth()->guard('admin')->check() || $resume->resume_status == 1 || $companyLookResume == 1) {

            $resumeArr = $resume->toArray();

            //最后登录时间
            $lastLoginTime = $resume->updatetime;
            $resumeArr['lastlogintime'] = substr($lastLoginTime, 0, 10);

            //头像
            $default_avatar=$resumeArr['sex']==1?asset('default/images/personal/headPortrait.jpg'):asset('default/images/personal/woman.jpg');
            if($resumeArr['chkphoto_open']==0){
                $resumeArr['avatar'] =  ($resumeArr['avatar']) ? asset('upload/personalavatar/'.$resumeArr['avatar']) : $default_avatar;
            }else{
                $resumeArr['avatar'] =$default_avatar;
            }
            //基本信息json
            //$currTime = date('Y-m-d');          //当前时间
            $age = birthday($resumeArr['birthday']);    //年龄

            //这里是英文版-工作地区
            $jobarea1 = ($resumeArr['jobarea1']) ? EnCollArea::getAreaName($resumeArr['jobarea1']) : '';
            $jobarea2 = ($resumeArr['jobarea2']) ? EnCollArea::getAreaName($resumeArr['jobarea2']) : '';
            $jobarea3 = ($resumeArr['jobarea3']) ? EnCollArea::getAreaName($resumeArr['jobarea3']) : '';
            $jobarea4 = ($resumeArr['jobarea4']) ? EnCollArea::getAreaName($resumeArr['jobarea4']) : '';
            $jobarea5 = ($resumeArr['jobarea5']) ? EnCollArea::getAreaName($resumeArr['jobarea5']) : '';
            $jobarea = $jobarea1 . ',' . $jobarea2 . ',' . $jobarea3 . ',' . $jobarea4 . ',' . $jobarea5;

            //这里是英文版-工地岗位
            $jobsort1 = ($resumeArr['jobsort1']) ? EnCollPosition::getPosName($resumeArr['jobsort1']) : '';
            $jobsort2 = ($resumeArr['jobsort2']) ? EnCollPosition::getPosName($resumeArr['jobsort2']) : '';
            $jobsort3 = ($resumeArr['jobsort3']) ? EnCollPosition::getPosName($resumeArr['jobsort3']) : '';
            $jobsort4 = ($resumeArr['jobsort4']) ? EnCollPosition::getPosName($resumeArr['jobsort4']) : '';
            $jobsort5 = ($resumeArr['jobsort5']) ? EnCollPosition::getPosName($resumeArr['jobsort5']) : '';
            $jobsort = $jobsort1 . ',' . $jobsort2 . ',' . $jobsort3 . ',' . $jobsort4 . ',' . $jobsort5;

            //这里是英文版
            $resumeArr3 = array(
                'job_status' => EnCollOption::getOptionName($resumeArr['job_status'], 'job_status'),
                'education' => EnCollOption::getOptionName($resumeArr['education'], 'education'),
                'work_year' => ($resumeArr['work_year']) ? EnCollOption::getOptionName($resumeArr['work_year'], 'work_year') : "inexperience",
                'expectedsalary' => ($resumeArr['expectedsalary']) ? EnCollOption::getOptionName($resumeArr['expectedsalary'], 'expectedsalary') . 'Yuan/month' : 'Negotiable',
                'homeaddress' => EnCollArea::getAreaAddress($resumeArr['homeaddress']),
                'phoneAddress' => EnCollArea::getAreaName(substr($resumeArr['homeaddress'], 0, 2) . '0000'),
                'jobarea' => trim($jobarea, ','),
                'jobsort' => trim($jobsort, ','),
                'sex' => ($resumeArr['sex'] == '1') ? 'Man' : 'Woman',
                'birthday' => $age . 'Year',
                'census' => ($resumeArr['census']) ? EnCollArea::getAreaAddress($resumeArr['census']) : 'Unfilled',
                'marital' => ($resumeArr['marital']) ? EnCollOption::getOptionName($resumeArr['marital'], 'marital') : 'Unfilled',
                'height' => ($resumeArr['height']) ? $resumeArr['height'] . 'cm' : 'Unfilled',
                'avatar' => $resumeArr['avatar']
            );
            $reArrEn = array_merge($resumeArr, $resumeArr3);

            $resumeJsonEn = json_encode($resumeArr);

            //---英文版求职意向--------------------------------------------------------------------------------------------------------------------
            $jobarea = $jobarea1 . '+' . $jobarea2 . '+' . $jobarea3 . '+' . $jobarea4 . '+' . $jobarea5;
            $jobsort = $jobsort1 . '+' . $jobsort2 . '+' . $jobsort3 . '+' . $jobsort4 . '+' . $jobsort5;
            $objectiveArrEn = array(
                'intentionjobs' => $resumeArr['intentionjobs'],
                'isexpectedsalary' => $resumeArr['isexpectedsalary'],
                'jobarea1' => $resumeArr['jobarea1'],
                'jobarea2' => $resumeArr['jobarea2'],
                'jobarea3' => $resumeArr['jobarea3'],
                'jobarea4' => $resumeArr['jobarea4'],
                'jobarea5' => $resumeArr['jobarea5'],
                'jobarea' => trim($jobarea, '+'),
                'jobsort1' => $resumeArr['jobsort1'],
                'jobsort2' => $resumeArr['jobsort2'],
                'jobsort3' => $resumeArr['jobsort3'],
                'jobsort4' => $resumeArr['jobsort4'],
                'jobsort5' => $resumeArr['jobsort5'],
                'jobsort' => trim($jobsort, '+'),
                'expectedsalary' => ($resumeArr['expectedsalary']) ? EnCollOption::getOptionName($resumeArr['expectedsalary'], 'expectedsalary') : '',
            );
            $objectiveJsonEn = json_encode($objectiveArrEn);

            $workExp = ResumeWorkExp::where('resume_id',$resume->id)->orderBy('updatetime','desc')->get()->toArray();
            //英文版工作经历
            $workExpArrEn = [];
            if (count($workExp) > 0) {
                foreach ($workExp as $v) {
                    $arr = array(
                        'industry' => ($v['industry']) ? EnCollOption::getOptionName($v['industry'], 'industry') : "",
                        'comkind' => EnCollOption::getOptionName($v['comkind'], 'comkind'),
                        'scale' => EnCollOption::getOptionName($v['scale'], 'employee_num'),
                        'starttime' => substr($v['starttime'], 0, 7),
                        'endtime' => ($v['endtime'] == '0000-00-00') ? '至今' : substr($v['endtime'], 0, 7)
                    );
                    $workExpArrEn[] = array_merge($v, $arr);
                }
            }

            $eduExp = ResumeEducationExp::where('resume_id',$resume->id)->orderBy('updatetime','desc')->get()->toArray();
            //英文版教育经历
            $eduExpArrEn = [];
            if (count($eduExp) > 0) {
                foreach ($eduExp as $v) {
                    $arr = array(
                        'education' => EnCollOption::getOptionName($v['education'], 'education'),
                        'starttime' => substr($v['starttime'], 0, 7),
                        'endtime' => ($v['endtime'] == '0000-00-00') ? '至今' : substr($v['endtime'], 0, 7)
                    );
                    $eduExpArrEn[] = array_merge($v, $arr);
                }
            }

            //---项目经验-------------------------------------------------------------------------------------------------------------------------------------------------------
            $projectExp = ResumeProjectExp::where('resume_id',$resume->id)->orderBy('updatetime','desc')->get()->toArray();
            $projectExpArr = [];
            if(count($projectExp) > 0){
                foreach($projectExp as $v){
                    $arr=array(
                        'starttime' => substr($v['starttime'],0,7),
                        'endtime' => ($v['endtime'] == '0000-00-00') ? '至今' : substr($v['endtime'],0,7)
                    );
                    $projectExpArr[] = array_merge($v,$arr);
                }
            }

            $language = ResumeLanguageSkill::where('resume_id',$resume->id)->orderBy('id')->get()->toArray();
            //英文版语言能力
            $languageArrEn = [];
            if (count($language) > 0) {
                foreach ($language as $v) {
                    $arr = array(
                        'language' => EnCollOption::getOptionName($v['language'], 'language'),
                        'degree' => EnCollOption::getOptionName($v['degree'], 'degree'),
                        'level' => EnCollTwoOption::getTwoOptionName($v['level'], 'language')
                    );
                    $languageArrEn[] = array_merge($v, $arr);
                }
            }
            $languageJsonEn = json_encode($language);


            $skill = ResumeSkill::where('resume_id',$resume->id)->orderBy('id')->get()->toArray();
            //英文版技能专长
            $skillArrEn = [];
            if (count($skill) > 0) {
                foreach ($skill as $v) {
                    $arr = array(
                        'degree' => EnCollOption::getOptionName($v['degree'], 'degree')
                    );
                    $skillArrEn[] = array_merge($v, $arr);
                }
            }
            $skillJsonEn = json_encode($skill);

//---证书-------------------------------------------------------------------------------------------------------------------------------------------------------
            $certificate = ResumeCertificate::where('resume_id', $resume->id)->orderBy('id')->get()->toArray();
            $certificateArr = [];
            if (count($certificate) > 0) {
                foreach ($certificate as $v) {
                    $arr = array(
                        'gettime' => substr($v['gettime'], 0, 4)
                    );
                    $certificateArr[] = array_merge($v, $arr);
                }
            }
            $certificateJson = json_encode($certificate);


            //---其它信息-------------------------------------------------------------------------------------------------------------------------------------------------------
            $otherArr = ResumeOther::where('resume_id', $resume->id)->orderBy('updatetime', 'desc')->get()->toArray();
            $otherJson = json_encode($otherArr);

            //---我的作品-------------------------------------------------------------------------------------------------------------------------------------------------------
            $photoJson = [];
            $works = ResumeWorks::where('resume_id', $resume->id)->orderBy('updatetime', 'desc')->get()->toArray();
            $worksArr = [];
            $worksType = ['gif', 'jpg', 'jpeg', 'bmp', 'png'];
            foreach ($works as $k => $v) {
                $worksImgArr = ResumeWorksImg::where('resume_id', $resume->id)->where('works_id', $v['id'])->orderBy('updatetime', 'desc')->get()->toArray();
                foreach ($worksImgArr as $kk => $vv) {
                    $suffix = substr(strrchr($vv['imgurl'], '.'), 1);
                    if (in_array($suffix, $worksType)) {
                        $imgurl = 'upload/personalworks/' . $vv['imgurl'];
                    } else {
                        switch ($suffix) {
                            case 'doc' :
                                $imgurl = 'default/images/personal/doc.jpg';
                                break;
                            case 'docx' :
                                $imgurl = 'default/images/personal/doc.jpg';
                                break;
                            case 'ppt' :
                                $imgurl = 'default/images/personal/ppt.jpg';
                                break;
                            case 'pptx' :
                                $imgurl = 'default/images/personal/ppt.jpg';
                                break;
                            case 'xls' :
                                $imgurl = 'default/images/personal/xls.jpg';
                                break;
                            case 'xlsx' :
                                $imgurl = 'default/images/personal/xls.jpg';
                                break;
                            case 'pdf' :
                                $imgurl = 'default/images/personal/pdf.jpg';
                                break;
                            case 'txt' :
                                $imgurl = 'default/images/personal/txt.jpg';
                                break;
                            default :
                                $imgurl = '未知';
                                break;
                        }
                    }
                    if ($kk == '0') {
                        $v['imgurl'] = asset($imgurl);
                    }
                    $v['allfile'][] = array(
                        'fileUrlImg' => $imgurl,
                        'fileCon' => 'upload/personalworks/' . $vv['imgurl'],
                    );
                    //图片查看
                    $v['photo'][] = array(
                        'alt' => "<a target='_blank' href='" . asset('upload/personalworks/' . $vv['imgurl']) . "'>下载源文件</a>",
                        "pid" => $vv['id'], //图片id
                        "src" => asset($imgurl), //原图地址
                        "thumb" => asset($imgurl)  //缩略图地址
                    );
                    $v['photoJson'] = $v['photo'];
                }
                $worksArr[] = $v;
                $photoJson[$v['id']] = $v['photoJson'];
            }

            $photoJson = json_encode($photoJson);

            //右边浮动简历库小窗口
            $jsName = '';
            $jsUrl = '';
            $jsId = '';
            if (!empty($suid)) {
                $link = explode(',', $suid);
                foreach ($link as $k => $v) {
                    $link[$v] = idDecryption($v);
                }
                $resumelist = Resume::select('name', 'id')->whereIn('id', $link)->orderBy('updatetime','desc')->orderBy('id','desc')->get();
                foreach ($resumelist as $k => $v) {
                    $v->url = url("resume_" . idEncryption($v->id) . ".html?suid=" . $suid);
                    $jsName .= $v->name . '|';
                    //$jsUrl .=   url("resume?suid=$suid&id=".$v->id).'|';
                    $jsUrl .= url("resume_" . idEncryption($v->id) . ".html?suid=" . $suid) . '|';
                    $jsId .= $v->id . '|';
                }
            }

            //简历查看状态
            if (empty($user->uid)) {
                $lookStatus = 0;
            } else {

                $lookStatus = $this->lookResumeStatus($user->uid, $id);

                $ResumeSend = ResumeSend::select('created_at')->where("resume_id", $id)->where('company_uid', $user->uid)
                    ->orderBy('created_at', 'desc')->first();

                if ($ResumeSend) {
                    $zero1 = strtotime($ResumeSend->created_at);
                    $zero2 = strtotime($user->viptime);
                    $time_c = $zero2 - $zero1;

                    if ($time_c > 0) {
                        $lookStatus = 2;
                    }
                }

            }
            // 预览简历时操作
            $personalUser = auth()->guard('personal')->user();
            if(!empty($personalUser)){
                $resume = Resume::where("id",$id)->where('uid',$personalUser->uid)->first();
                if(!empty($resume)){
                    $lookStatus = 3;
                }
            }

            if (!empty($user->uid) and is_numeric($user->uid)) {//登录
                $look_button = "button1";//查看联系方式button
                $interview_button = "button2"; //邀请面试
                $insertPersonnelLibrary_button = "button3";//纳入人才库
                //查看是否已加入人才库
                $haveFavorite = ResumeFavorite::where("uid", $user->uid)->where("resume_id", $id)->first();
                if ($haveFavorite) {
                    if ($haveFavorite->status == 4) {//4代表已软删除
                        $insertPersonnelLibrary_text = "IntoPool";
                    } else {
                        $insertPersonnelLibrary_text = "HasPool";
                    }
                } else {
                    $insertPersonnelLibrary_text = "IntoPool";
                }

                //添加企业浏览简历记录
                if ($CompanyBasic) {
                    if (!BrowseResume::where("com_id", $CompanyBasic->id)->where("company_uid", $user->uid)->where("resume_id", $id)->first()) {
                        $addBrowseResume = [];
                        $addBrowseResume["company_uid"] = $user->uid;
                        $addBrowseResume["com_id"] = $CompanyBasic->id;
                        $addBrowseResume["personal_uid"] = $resume->uid;
                        $addBrowseResume["resume_id"] = $id;
                        BrowseResume::create($addBrowseResume);
                    }
                }

                //查询该简历是否给企业投过
                $ResumeSend = ResumeSend::where('company_uid', $user->uid)->where('resume_id', $id)->orderBy('created_at', 'desc')
                    ->where('status', 0)->get();
                if (count($ResumeSend) > 0) {
                    ResumeSend::where('company_uid', $user->uid)->where('resume_id', $id)->update(['status' => 1]);
                }

            } else {//未登录
                $look_button = "companylogin";
                $interview_button = "companylogin2";
                $insertPersonnelLibrary_button = "companylogin3";
                $insertPersonnelLibrary_text = "IntoPool";

            }
            //找人才标题
            $jobsortall = trim($resumeArr['intentionjobs'] . "," . $jobsort1 . ',' . $jobsort2 . ',' . $jobsort3 . ',' . $jobsort4 . ',' . $jobsort5, ',');
            //英文标题
            $find_jobEn = $jobarea1 . 'Look' . $jobsortall . 'Work,' . $resumeArr['id'] . 'Resume';

            return Style::view('index.english.resume', compact('reArrEn', 'resumeJsonEn', 'objectiveJsonEn', 'evaluationJson', 'workExpArrEn', 'eduExpArrEn', 'projectExpArr',
                'languageArrEn', 'languageJsonEn', 'skillArrEn', 'skillJsonEn', 'certificateArr', 'certificateJson', 'otherArr', 'otherJson', 'worksArr', 'photoJson',
                'resumelist', 'id', 'look_button', 'interview_button', 'interviewHtml', 'contactHtml', 'jsName', 'jsUrl', 'jsId', 'lookStatus',
                'insertPersonnelLibrary_button', 'insertPersonnelLibrary_text', 'find_jobEn'));

         }else{//没有权限处理
            abort(404);
          }

        }


    /**简历中文显示**/
    public function chinese($resume,Request $request){
        //用户ID
        $suid =  $request->input('suid');
        //读取基本信息
        $id=$resume->id;

        //判断能浏览简历的参数 管理员可以，自己可以，简历状态为1
        $user=auth()->guard('company')->user();//企业登录
        if(auth()->guard('company')->check()){

            //是否简历备注开始
            $resumeRemark = ResumeRemark::where("company_uid",$user->uid)->where("resume_id",$id)->first();
            $companyJob   = CompanyJob::where("uid",$user->uid)->where('job_status',1)->get();//该公司发布职位记录
            if(!empty($resumeRemark)){
                $obj = CompanyJob::where("id",$resumeRemark->job_id)->first(); 
                $resumeRemark->job_name = $obj->job_title;
            }
            //是否备注结束

            $CompanyBasic = CompanyBasic::select("id")->where("uid",$user->uid)->orderBy("updatetime","desc")->first();//是否给企业投递过简历
            if($CompanyBasic){
                if(ResumeSend::where("company_uid",$user->uid)->where("com_id",$CompanyBasic->id)->where("personal_uid",$resume->uid)->where("resume_id",$id)->count()){
                    $companyLookResume = 1;
                }else{
                    $companyLookResume = 0;
                }
            }else{
                $companyLookResume = 0;
            }
        }else{
            $companyLookResume = 0;
        }



        if(auth()->guard('personal')->check()){//用户登录
            $personalUid = auth()->guard('personal')->user()->uid;
        }else{
            $personalUid = '';
        }

        //判断条件是否有权浏览
        if($personalUid == $resume->uid || auth()->guard('admin')->check() || $resume->resume_status == 1 || $companyLookResume == 1){

            $resumeArr = $resume->toArray();

            //最后登录时间
            $lastLoginTime =$resume->updatetime;
            $resumeArr['lastlogintime']=substr($lastLoginTime,0,10);

            //头像
            $default_avatar=$resumeArr['sex']==1?asset('default/images/personal/headPortrait.jpg'):asset('default/images/personal/woman.jpg');
            if($resumeArr['chkphoto_open']==0){
                $resumeArr['avatar'] =  ($resumeArr['avatar']) ? asset('upload/personalavatar/'.$resumeArr['avatar']) : $default_avatar;
            }else{
                $resumeArr['avatar'] =$default_avatar;
            }
            //基本信息json
            //$currTime = date('Y-m-d');          //当前时间
            $age = birthday($resumeArr['birthday']);    //年龄

            //工地地区
            $jobarea1 = ($resumeArr['jobarea1']) ?  CollArea::getAreaName($resumeArr['jobarea1']) : '';
            $jobarea2 = ($resumeArr['jobarea2']) ?  CollArea::getAreaName($resumeArr['jobarea2']) : '';
            $jobarea3 = ($resumeArr['jobarea3']) ?  CollArea::getAreaName($resumeArr['jobarea3']) : '';
            $jobarea4 = ($resumeArr['jobarea4']) ?  CollArea::getAreaName($resumeArr['jobarea4']) : '';
            $jobarea5 = ($resumeArr['jobarea5']) ?  CollArea::getAreaName($resumeArr['jobarea5']) : '';
            $jobarea = $jobarea1 . ',' . $jobarea2 . ',' . $jobarea3 . ','  . $jobarea4 . ','  . $jobarea5;

            //工地岗位
            $jobsort1 = ($resumeArr['jobsort1']) ?  CollPosition::getPosName($resumeArr['jobsort1']) : '';
            $jobsort2 = ($resumeArr['jobsort2']) ?  CollPosition::getPosName($resumeArr['jobsort2']) : '';
            $jobsort3 = ($resumeArr['jobsort3']) ?  CollPosition::getPosName($resumeArr['jobsort3']) : '';
            $jobsort4 = ($resumeArr['jobsort4']) ?  CollPosition::getPosName($resumeArr['jobsort4']) : '';
            $jobsort5 = ($resumeArr['jobsort5']) ?  CollPosition::getPosName($resumeArr['jobsort5']) : '';
            $jobsort = $jobsort1 . ',' . $jobsort2 . ',' . $jobsort3 . ','  . $jobsort4 . ','  . $jobsort5;


            $resumeArr2=array(
                'job_status' => CollOption::getOptionName($resumeArr['job_status'],'job_status'),
                'education' => CollOption::getOptionName($resumeArr['education'],'education'),
                'work_year' => ($resumeArr['work_year']) ? CollOption::getOptionName($resumeArr['work_year'],'work_year') : "无经验",
                'expectedsalary' => ($resumeArr['expectedsalary']) ? CollOption::getOptionName($resumeArr['expectedsalary'],'expectedsalary').'元/月' : '面议',
                'homeaddress' => CollArea::getAreaAddress($resumeArr['homeaddress']),
                'phoneAddress' => CollArea::getAreaName(substr($resumeArr['homeaddress'],0,2).'0000'),
                'jobarea' =>  trim($jobarea,','),
                'jobsort' =>  trim($jobsort,','),
                'sex' => ($resumeArr['sex'] == '1') ? '男' : '女',
                'birthday' => $age.'岁',
                'census' => ($resumeArr['census']) ? CollArea::getAreaAddress($resumeArr['census']) : '未填写',
                'marital' => ($resumeArr['marital']) ? CollOption::getOptionName($resumeArr['marital'],'marital') : '未填写',
                'height' => ($resumeArr['height']) ? $resumeArr['height'] . 'cm' : '未填写',
                'avatar' => $resumeArr['avatar']
            );
            $reArr = array_merge($resumeArr,$resumeArr2);

            $resumeJson = json_encode($resumeArr);


            //---求职意向--------------------------------------------------------------------------------------------------------------------
            $jobarea = $jobarea1 . '+' . $jobarea2 . '+' . $jobarea3 . '+'  . $jobarea4 . '+'  . $jobarea5;
            $jobsort = $jobsort1 . '+' . $jobsort2 . '+' . $jobsort3 . '+'  . $jobsort4 . '+'  . $jobsort5;
            $objectiveArr = array(
                'intentionjobs' => $resumeArr['intentionjobs'],
                'isexpectedsalary' => $resumeArr['isexpectedsalary'],
                'jobarea1' => $resumeArr['jobarea1'],
                'jobarea2' => $resumeArr['jobarea2'],
                'jobarea3' => $resumeArr['jobarea3'],
                'jobarea4' => $resumeArr['jobarea4'],
                'jobarea5' => $resumeArr['jobarea5'],
                'jobarea'  => trim($jobarea,'+'),
                'jobsort1' => $resumeArr['jobsort1'],
                'jobsort2' => $resumeArr['jobsort2'],
                'jobsort3' => $resumeArr['jobsort3'],
                'jobsort4' => $resumeArr['jobsort4'],
                'jobsort5' => $resumeArr['jobsort5'],
                'jobsort'  => trim($jobsort,'+'),
                'expectedsalary' => ($resumeArr['expectedsalary']) ? CollOption::getOptionName($resumeArr['expectedsalary'],'expectedsalary') : '',
            );
            $objectiveJson = json_encode($objectiveArr);

            //---自我评价--------------------------------------------------------------------------------------------------------------------
            $objectiveArr = array(
                'introduction' => $resumeArr['introduction']
            );
            $evaluationJson = json_encode($objectiveArr);

            //---工作经历--------------------------------------------------------------------------------------------------------------------
            $workExp = ResumeWorkExp::where('resume_id',$resume->id)->orderBy('updatetime','desc')->get()->toArray();
            $workExpArr = [];
            if(count($workExp) > 0){
                foreach($workExp as $v){
                    $arr=array(
                        'industry' => ($v['industry']) ? CollOption::getOptionName($v['industry'],'industry') : "",
                        'comkind' => CollOption::getOptionName($v['comkind'],'comkind'),
                        'scale' => CollOption::getOptionName($v['scale'],'employee_num'),
                        'starttime' => substr($v['starttime'],0,7),
                        'endtime' => ($v['endtime'] == '0000-00-00') ? '至今' : substr($v['endtime'],0,7)
                    );
                    $workExpArr[] = array_merge($v,$arr);
                }
            }


            //---教育经历------------------------------------------------------------------------------------------------------------------------------------------------------
            $eduExp = ResumeEducationExp::where('resume_id',$resume->id)->orderBy('updatetime','desc')->get()->toArray();
            $eduExpArr = [];
            if(count($eduExp) > 0){
                foreach($eduExp as $v){
                    $arr=array(
                        'education' => CollOption::getOptionName($v['education'],'education'),
                        'starttime' => substr($v['starttime'],0,7),
                        'endtime' => ($v['endtime'] == '0000-00-00') ? '至今' : substr($v['endtime'],0,7)
                    );
                    $eduExpArr[] = array_merge($v,$arr);
                }
            }

            //---项目经验-------------------------------------------------------------------------------------------------------------------------------------------------------
            $projectExp = ResumeProjectExp::where('resume_id',$resume->id)->orderBy('updatetime','desc')->get()->toArray();
            $projectExpArr = [];
            if(count($projectExp) > 0){
                foreach($projectExp as $v){
                    $arr=array(
                        'starttime' => substr($v['starttime'],0,7),
                        'endtime' => ($v['endtime'] == '0000-00-00') ? '至今' : substr($v['endtime'],0,7)
                    );
                    $projectExpArr[] = array_merge($v,$arr);
                }
            }


            //---语言能力-------------------------------------------------------------------------------------------------------------------------------------------------------
            $language = ResumeLanguageSkill::where('resume_id',$resume->id)->orderBy('id')->get()->toArray();
            $languageArr = [];
            if(count($language) > 0){
                foreach($language as $v){
                    $arr=array(
                        'language' => CollOption::getOptionName($v['language'], 'language'),
                        'degree' => CollOption::getOptionName($v['degree'], 'degree'),
                        'level' => CollTwoOption::getTwoOptionName($v['level'], 'language')
                    );
                    $languageArr[] = array_merge($v,$arr);
                }
            }
            $languageJson = json_encode($language);

            //---技能专长-------------------------------------------------------------------------------------------------------------------------------------------------------
            $skill = ResumeSkill::where('resume_id',$resume->id)->orderBy('id')->get()->toArray();
            $skillArr = [];
            if(count($skill) > 0){
                foreach($skill as $v){
                    $arr=array(
                        'degree' => CollOption::getOptionName($v['degree'],'degree')
                    );
                    $skillArr[] = array_merge($v,$arr);
                }
            }
            $skillJson = json_encode($skill);


            //---证书-------------------------------------------------------------------------------------------------------------------------------------------------------
            $certificate = ResumeCertificate::where('resume_id',$resume->id)->orderBy('id')->get()->toArray();
            $certificateArr = [];
            if(count($certificate) > 0){
                foreach($certificate as $v){
                    $arr=array(
                        'gettime' => substr($v['gettime'],0,4)
                    );
                    $certificateArr[] = array_merge($v,$arr);
                }
            }
            $certificateJson = json_encode($certificate);


            //---其它信息-------------------------------------------------------------------------------------------------------------------------------------------------------
            $otherArr = ResumeOther::where('resume_id',$resume->id)->orderBy('updatetime','desc')->get()->toArray();
            $otherJson = json_encode($otherArr);

            //---我的作品-------------------------------------------------------------------------------------------------------------------------------------------------------
            $photoJson = [];
            $works = ResumeWorks::where('resume_id',$resume->id)->orderBy('updatetime','desc')->get()->toArray();
            $worksArr = [];
            $worksType = ['gif','jpg','jpeg','bmp','png'];
            foreach($works as $k => $v){
                $worksImgArr = ResumeWorksImg::where('resume_id',$resume->id)->where('works_id',$v['id'])->orderBy('updatetime','desc')->get()->toArray();
                foreach($worksImgArr as $kk => $vv){
                    $suffix =  substr(strrchr( $vv['imgurl'], '.'), 1);
                    if(in_array($suffix,$worksType)){
                        $imgurl = 'upload/personalworks/'.$vv['imgurl'];
                    }else{
                        switch($suffix){
                            case 'doc' : $imgurl = 'default/images/personal/doc.jpg'; break;
                            case 'docx' : $imgurl = 'default/images/personal/doc.jpg'; break;
                            case 'ppt' : $imgurl = 'default/images/personal/ppt.jpg'; break;
                            case 'pptx' : $imgurl = 'default/images/personal/ppt.jpg'; break;
                            case 'xls' : $imgurl = 'default/images/personal/xls.jpg'; break;
                            case 'xlsx' : $imgurl = 'default/images/personal/xls.jpg'; break;
                            case 'pdf' : $imgurl = 'default/images/personal/pdf.jpg'; break;
                            case 'txt' : $imgurl = 'default/images/personal/txt.jpg'; break;
                            default : $imgurl = '未知'; break;
                        }
                    }
                    if($kk == '0'){
                        $v['imgurl'] = asset($imgurl);
                    }
                    $v['allfile'][] = array(
                        'fileUrlImg' =>$imgurl,
                        'fileCon' =>'upload/personalworks/'.$vv['imgurl'],
                    );
                    //图片查看
                    $v['photo'][] = array(
                        'alt' => "<a target='_blank' href='".asset('upload/personalworks/'.$vv['imgurl'])."'>下载源文件</a>",
                        "pid" => $vv['id'], //图片id
                        "src" => asset($imgurl), //原图地址
                        "thumb"=> asset($imgurl)  //缩略图地址
                    );
                    $v['photoJson'] = $v['photo'];
                }
                $worksArr[] = $v;
                $photoJson[$v['id']] = $v['photoJson'];
            }

            $photoJson = json_encode($photoJson);

            //右边浮动简历库小窗口
            $jsName = '';$jsUrl = ''; $jsId = '';
            if(!empty($suid)){
                $link = explode(',',$suid);
                $in=array();
                foreach($link as $k => $v){
                    $in[$v] = idDecryption($v);
                }
                $resumelist = Resume::select('name', 'id')->whereIn('id', $in)->orderBy('updatetime','desc')->orderBy('id','desc')->get();
                foreach($resumelist as $k => $v){
                    $v->url = url("resume_".idEncryption($v->id).".html?suid=".$suid) ;
                    $jsName .=   $v->name.'|';
                    //$jsUrl .=   url("resume?suid=$suid&id=".$v->id).'|';
                    $jsUrl .=   url("resume_".idEncryption($v->id).".html?suid=".$suid).'|';
                    $jsId .=   $v->id.'|';
                }
            }

            //简历查看状态
            if(empty($user->uid)){
                $lookStatus = 0;
            }else{
                //是不是已经被查看
                $lookStatus = $this->lookResumeStatus($user->uid,$id);
                //是不是已经投递 并且该企业必须是会员才能查看
                $ResumeSend = ResumeSend::select('created_at')->where("resume_id",$id)->where('company_uid',$user->uid)->first();
                if(!empty($ResumeSend)){
                    if($user->viptime > date('Y-m-d H:i:s')){
                        $lookStatus = 2;
                    }
                }
            }
            // 预览简历时操作
            $personalUser = auth()->guard('personal')->user();
            if(!empty($personalUser)){
                $resumeInfo = Resume::where("id",$id)->where('uid',$personalUser->uid)->first();
                if(!empty($resumeInfo)){
                    $lookStatus = 3;
                }
            }
            if(!empty($user->uid) and is_numeric($user->uid)){//登录
                $look_button = "button1";//查看联系方式button
                $interview_button = "button2"; //邀请面试
                $insertPersonnelLibrary_button = "button3";//纳入人才库
                //查看是否已加入人才库
                $haveFavorite = ResumeFavorite::where("uid",$user->uid)->where("resume_id",$id)->first();
                if($haveFavorite){
                    if($haveFavorite->status == 4){//4代表已软删除
                        $insertPersonnelLibrary_text = "纳入人才库";
                    }else{
                        $insertPersonnelLibrary_text = "已纳入人才库";
                    }
                }else{
                    $insertPersonnelLibrary_text = "纳入人才库";
                }

                //添加企业浏览简历记录
                if(!empty($CompanyBasic)){
                    if(!BrowseResume::where("com_id",$CompanyBasic->id)->where("company_uid",$user->uid)->where("resume_id",$id)->first()){
                        $addBrowseResume = [];
                        $addBrowseResume["company_uid"] = $user->uid;
                        $addBrowseResume["com_id"] = $CompanyBasic->id;
                        $addBrowseResume["personal_uid"] = $resume->uid;
                        $addBrowseResume["resume_id"] = $id;
                        BrowseResume::create($addBrowseResume);
                    }
                }

                //查询该简历是否给企业投过
                $ResumeSend = ResumeSend::where('company_uid',$user->uid)->where('resume_id',$id)->orderBy('created_at','desc')
                    ->where('status',0)->get();
                if(count($ResumeSend) > 0){
                    ResumeSend::where('company_uid',$user->uid)->where('resume_id',$id)->update(['status'=>1]);
                }

            }else{//未登录
                $look_button = "companylogin";
                $interview_button = "companylogin2";
                $insertPersonnelLibrary_button = "companylogin3";
                $insertPersonnelLibrary_text = "纳入人才库";

            }
            //找人才标题
            $jobsortall = trim($resumeArr['intentionjobs'].",".$jobsort1.','.$jobsort2.','.$jobsort3.','.$jobsort4.','.$jobsort5,',');
            $find_job = $jobarea1.'找'.$jobsortall.'工作,'.$resumeArr['id'].'的个人简历';


            return Style::view('index.resume',compact('resumeRemark', 'companyJob', 'reArr','resumeJson','objectiveJson','evaluationJson','workExpArr','eduExpArr','projectExpArr',
                'languageArr','languageJson','skillArr','skillJson','certificateArr','certificateJson','otherArr','otherJson','worksArr','photoJson',
                'resumelist','id','look_button','interview_button','interviewHtml','contactHtml','jsName','jsUrl','jsId','lookStatus',
                'insertPersonnelLibrary_button','insertPersonnelLibrary_text','find_job','user'));
        }else{//没有权限处理
            abort(404);
        }
    }
    /**
     * 预览人才简历
     * @param $id
     * @param Request $request
     * @return mixed
     */
    public function index($id,Request $request){

        $id = idDecryption($id);
        $resume = Resume::where('id',$id)->first();
        if(!isset($resume)){//没有这份简历转404
            abort(404);
        }
        if($resume->language=='en'){
            //简历英文调用
            return $this->english($resume,$request);
        }else{
            //简历中文调用
            return $this->chinese($resume,$request);
        }

    }

    /**
     * 返回简历是否被购买查看
     * @param $uid
     * @param $resumeId
     * @return int
     */
    public function lookResumeStatus($uid,$resumeId){
        if(!empty($uid)){
             $BuyResume = BuyResume::where('company_uid',$uid)->where('resume_id',$resumeId)->first();
             if($BuyResume){
                    $lookStatus=1;//简历被购买查看过
             }else{
                    $lookStatus=0;//简历未被查看过
             }
        }else{
           $lookStatus=0;//未登录
        }
        return $lookStatus;
    }

    /**
     * 时间差
     * @param $time
     * @return int
     */
    public function timediff($time){
        $timezone = Config::get('app.timezone','PRC');
        date_default_timezone_set($timezone);
        $zero1 = strtotime(date("Y-m-d H:i:s",time()));
        $zero2 = strtotime($time);
        $time_c = $zero2-$zero1;
        return $time_c;
    }

}